$(function (){
    $('#top-two').load('/front/top-two.html')
    $('#foot').load('/front/foot.html')

//    获取新闻类型
    $.get({
        url: '/productType/find',
        dataType: 'json',
        success(res){
            let productType=$('#productType')
            if(res.data.length>0){
                productType.empty();
                for (const datum of res.data) {
                    let div='<div onclick="getProduct('+datum.id+')">'+datum.productTypeName+'</div>'
                    productType.append(div)
                }
                //默认获取产品
                getProduct(res.data[0].id)
            }
        }
    })
})

function getProduct(val){
    $.get({
        url:'/product/find',
        data: 'productTypeID='+val,
        dataType: 'json',
        success(res) {
            let product=$('#product');
            product.empty();
            let count=0;
            if(res.data.length>0){
                for (const datum of res.data) {
                    count++;
                    let div='<div class="justify-content-center flex-wrap">\n' +
                        '                                    <img src="'+datum.imageLocation+'">\n' +
                        '                                    <div>'+datum.productName+'</div>\n' +
                        '                                    <div class="justify-content-center">\n' +
                        '                                        <div>价格：</div>\n' +
                        '                                        <div>￥'+datum.price+'</div>\n' +
                        '                                    </div>\n' +
                        '                                </div>'
                    product.append(div)
                    if(count>=8)
                        break;
                }
            }
        }
    })
}